﻿namespace VXCompany.SilverlightLogging.Services.ServiceContracts
{
	using System;
	using System.Runtime.Serialization;


	#region Enumerations

	/// <summary>
	/// Specifies possible error level values.
	/// </summary>
	public enum ErrorLevel
	{
		[EnumMember]
		Critical = 3,
		[EnumMember]
		Error = 2,
		[EnumMember]
		Warning = 1,
		[EnumMember]
		Informational = 0
	}

	/// <summary>
	/// Specifies possible SyncBehaviors values.
	/// </summary>
	[Flags]
	public enum SyncBehaviorFlags
	{
		[EnumMember]
		PerMinute = 1,
		[EnumMember]
		PerTwoMinutes = 2,
		[EnumMember]
		PerFiveMinutes = 4,
		[EnumMember]
		PerTenMinutes = 16,
		[EnumMember]
		PerFifteenMinutes = 32,
		[EnumMember]
		AppEnd = 64,
		[EnumMember]
		AppCrash = 128,
		[EnumMember]
		AppStart = 256
	}

	#endregion Enumerations

	/// <summary>
	/// Message for configuring logging settings at all clients.
	/// </summary>
	[DataContract]
	public class LoggingConfigurationMessage
	{
		#region Constructors

		/// <summary>
		/// Creates new instance, using default settings.
		/// </summary>
		public LoggingConfigurationMessage()
		{
			MinLogLevel = ErrorLevel.Critical;
			MinSyncLevel = ErrorLevel.Critical;
			SyncWhenStorageUnavailable = false;
		}

		#endregion Constructors

		#region Properties

		/// <summary>
		/// Gets or sets the client's ip address.
		/// </summary>
		[DataMember]
		public string ClientAddress
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the SyncBehaviors defining when errors are synchronised with the server.
		/// </summary>
		[DataMember]
		public SyncBehaviorFlags SyncBehaviorFlags
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the level from which errors are stored locally.
		/// </summary>
		[DataMember]
		public ErrorLevel MinLogLevel
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the level from which errors are synchronised with the server.
		/// </summary>
		[DataMember]
		public ErrorLevel MinSyncLevel
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets a value indicating whether messages must be sent to the service immediately, 
		/// when local storage is unavailable.
		/// </summary>
		[DataMember]
		public bool SyncWhenStorageUnavailable
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the authenticated user's ID.
		/// </summary>
		[DataMember]
		public string UserID
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets whether the user is authenticated.
		/// </summary>
		[DataMember]
		public bool IsUserAuthenticated
		{
			get;
			set;
		}

		#endregion Properties

		#region Methods

		public LoggingConfigurationMessage Clone()
		{
			return new LoggingConfigurationMessage()
			{
				ClientAddress = this.ClientAddress,
				SyncBehaviorFlags = this.SyncBehaviorFlags,
				MinLogLevel = this.MinLogLevel,
				MinSyncLevel = this.MinSyncLevel,
				SyncWhenStorageUnavailable = this.SyncWhenStorageUnavailable,
				UserID = this.UserID,
				IsUserAuthenticated = this.IsUserAuthenticated,
			};
		}

		#endregion Methods
	}
}